<template>
    <div >
        <el-form-item 
            :label="title"
            class="formDesignUserSelect"
        > <!--  -->
            <el-input
             v-model="text.pageShowValue"
             @change="showColumn">
                <template slot="append">
                    <span class="selectPeople" @click="setUserDialog">选择</span>
                </template>
            </el-input>
        </el-form-item>
        <selectUserComplete :visible.sync="setUserDialogVisible" @done="selectDone" />
    </div>
</template>

<script>
import selectUserComplete from "@/components/select/selectUserComplete"
export default {
    components:{selectUserComplete},
    name:'form-user-select',
    props:{
        title:{
            type:String,
            default:'选择人员'
        },
        column:{
            type:Object,
            default:()=>{}
        },
        value: [Array, String, Number, Object, Boolean],
    },
    data(){
        return {
            input1:'',
            setUserDialogVisible:false,
            text: undefined,
            first: false,
        }
    },
    methods:{
        showColumn(){
            console.log(this.column,'column>>>')
        },
        setUserDialog(){
            debugger
            this.setUserDialogVisible = true
        },
        selectDone(data){
            // account: "SDT13841"
            // realName: "林晓锋"
            // userId: "SDT13841"
            // userName: "林晓锋"
            // value: "林晓锋SDT13841"
            console.log(data,'>>>>>----')
            let objmap = this.column.objmap;
            this.text['pageShowValue'] = data[0]['realName']
            objmap.forEach(item => {
               this.text[item.key] = data[0][item.mapKey]
            })
            console.log(this.text,'this.text')
            debugger

        },
        getInitMap(){
            //this.$nextTick(()=>{
                debugger
                let obj = {};
                
                try{
                    let objmap = this.column.objmap;
                    
                    objmap.forEach(item => {
                        obj[item.key] = ''
                    })
                    obj['pageShowValue'] = ''
                    this.text = obj
                    debugger
                    //return obj
                }catch(e){
                    obj['pageShowValue'] = ''
                    this.text = obj
                }
                    
            //})
            
        }
    },
    watch: {
        text: {
            handler (val) {
                if (this.first || !this.validatenull(val)) {
                  this.first = true;
                  this.$emit('input', val);
                } else {
                  this.first = true;
                }
            }
        },
        value: {
            handler (val) {
                //debugger
                if(val){
                   this.text = val;
                }else{
                   this.getInitMap() //根据 column.objmap 生成初始数据
                }
            },
            immediate: true
        }
    },
}
</script>

<style lang="scss" >
    .pageHeader{
        font-size:18px;
        font-weight:bold;
        text-align: center;
        line-height:32px;
    }
    .selectPeople{
        cursor:pointer;
    }
</style>